import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Random;

public class GenerateAccessLog {
    public static void main(String[] args) throws IOException, InterruptedException {
        //准备数据
        //2,4,5 北京   17,18石家庄 23太原  54、55武汉  89合肥
        //150重庆  172,173,174西安
        int []ipTwo = {2,4,5,17,18,23,54,55,89,150,172,173,174};
        int[] ips = {123, 18, 123, 112, 181, 16, 172, 183, 190, 191, 196, 120};
        String[] requesTypes = {"GET", "POST"};
        String[] cursors = {"/vip/110", "/vip/111", "/vip/112", "/vip/113", "/vip/113", "/vip/113","/vip/114", "/vip/114" , "/free/210", "/free/211", "/free/212", "/free/213", "/free/213", "/company/310", "/company/311", "/company/312", "/company/312"};
        String[] references = {"www.baidu.com","www.baidu.com", "www.sougou.com", "www.biying.com", "www.google.com"};
        FileWriter fw = new FileWriter(args[0]);
        PrintWriter printWriter = new PrintWriter(fw);
        while (true) {
            Thread.sleep(100);
            //产生字段
            String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis());
            String method = requesTypes[getRandomNum(0, requesTypes.length)];
            String url = "/course" + cursors[getRandomNum(0, cursors.length)];
            String HTTPVERSION = "HTTP/1.1";
            String ip =  "10." + ipTwo[getRandomNum(0, ipTwo.length)] + "." + ips[getRandomNum(0, ips.length)] + "." + ips[getRandomNum(0, ips.length)];
            String reference = references[getRandomNum(0, references.length)];
            String rowLog = date + " " + method + " " + url + " " + HTTPVERSION + " " + ip + " " + reference;
            printWriter.println(rowLog);
            printWriter.flush();
        }
    }


    //[start,end)
    public static int getRandomNum(int start, int end) {
        int i = new Random().nextInt(end - start) + start;
        return i;
    }
}